<?php defined('SYSPATH') OR die('No direct access allowed.');

class Contmedlink_Controller extends Viewbase_Controller{
	
	public function __construct(){
		$this->modelname='contmedlink';	
		$this->controllername='contmedlink';
		$this->parent_column='content_id';
		$this->orderby=array('position'=>'');
		
		parent::__construct();	
	}	
	
		
	public function __postprocess_model($model){
		
		switch($this->input->post('formtype')){
			case 'multiple':
				$model->delete();
				if(count($this->input->post('media_id_array'))>0){
					foreach($this->input->post('media_id_array') as $mediaid){
						$model=ORM::factory('contmedlink');
						$model->media_id=$mediaid;
						$model->content_id=$this->input->post('content_id');
						$model->position=$this->input->post('position');
						$model->save();
						$this->__rewrite_positions($model);
					
					}
				}
				
			break;
			
			case 'single':
				/*
				$media=ORM::factory('media');
				$filedata=$media->upload_file('file');
				if($filedata!=NULL){
					$media->category_id=$this->input->post('category_id');
					$media->save();
					$model->media_id=$media->id;		
					
				}
				*/
			break;
			
		
		}
		
		
	}
	
	
}